
#ifndef QRREADER_H
#define QRREADER_H

#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <vector>
#include <QImage>

#include <iostream>
#include <vector>
#include <string>

#include "center.h"
#include "groupcenter.h"
#include "center.h"

using namespace cv;
using namespace std;

#define NUMERIC_MODE 1
#define ALPHA_NUMERIC_MODE 2
#define BINARY_MODE 4
#define JAPANESE_MODE 8

class qrReader
{

    public:
        qrReader ();
        void readQrCode (QImage *m);

    private:
        int pixelProportion;
        int versionINFO;
        int seed[5];
        int seed2[7][3];
        char eccLevel;
        int maskPatern;
        int rowTimming;
        int colTimming;
        int virtualOriginRow;
        int virtualOriginCol;

        vector<int> dataBlocks;

        center upperLeftCenter;
        center upperRightCenter;
        center lowerLeftCenter;

        int determinePixelProportion (QImage *m);
        int checkVersion (center c1, center c2, center c3, QImage* m);
        int checkExactVersion (center c1, center c2, QImage* m);

        vector<center> findCenters (QImage *m);
        vector<center> findPossibleCenters (QImage *m);
        void selectBestCenters (vector<center>);
        void checkHorizontal (int rowStart, int rowLimit, QImage *m, vector<center> *centerList);
        bool crossCheckVertical (int startRow, int startCol, QImage* m);
        bool checkRatio (int m[]);

        void findQuietZone (center c1, center c2, center c3, QImage* m);
        void findFormat (center c1, center c2, center c3, QImage* m);
        void findAlignments (center c, QImage* m);

        void unMask (int row, int col, QImage* m);
        vector<int> getDataBlocks (center c, QImage* m);
        vector<int> correctDataBlocks (vector<int> dataBlocks);
        String decodeDataBlocks ();

        String decodeNumeric (int sizeDataLenght);
        String decodeAlnum (int sizeDataLenght);
        String decodeBinary (int sizeDataLenght);
        String decodeJapanese (int sizeDataLenght);

        bool isPixelBlack (int row, int col, QImage* m);
        void paintPixel (int row, int col, QRgb color, QImage* m);
        void reversePixel (int row, int col, QImage* m);
        bool isPattern (int row, int col, QImage* m);

};

#endif // QRREADER_H


